﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Coomtools.commclass
{
    /// <summary>
    /// 对输入数据的约束检查类
    /// </summary>
    public static class checknumber
    {
        /// <summary>   
        /// 判断输入的字符串只包含数字   
        /// 可以匹配整数和浮点数   
        /// ^-?\d+$|^(-?\d+)(\.\d+)?$   
        /// </summary>   
        /// <param name="input"></param>   
        /// <returns></returns>   
        public static bool IsNumber(string input)
        {
            string pattern = "^-?\\d+$|^(-?\\d+)(\\.\\d+)?$";
            Regex regex = new Regex(pattern);
            return regex.IsMatch(input);
        }

        /// <summary>   
        /// 判断输入的字符串只包含数字   
        /// 可以匹配非负浮点数   
        /// "^\d+(\.\d+)?$" //非负浮点数（正浮点数 + 0） 
        /// </summary>   
        /// <param name="input"></param>   
        /// <returns></returns>   
        public static bool IsNotfufolat(string input)
        {
            string pattern = "^\\d+(\\.\\d+)?$";
            Regex regex = new Regex(pattern);
            return regex.IsMatch(input);
        }
        /// <summary>   
        /// 匹配非负整数   
        ///   
        /// </summary>   
        /// <param name="input"></param>   
        /// <returns></returns>   
        public static bool IsNotNagtive(string input)
        {
            Regex regex = new Regex(@"^\d+$");
            return regex.IsMatch(input);
        }
        /// <summary>   
        /// 匹配正整数   
        /// </summary>   
        /// <param name="input"></param>   
        /// <returns></returns>   
        public static bool IsUint(string input)
        {
            Regex regex = new Regex("^[0-9]*[1-9][0-9]*$");
            return regex.IsMatch(input);
        }
        /// <summary>   
        /// 判断输入的字符串字包含英文字母   
        /// </summary>   
        /// <param name="input"></param>   
        /// <returns></returns>   
        public static bool IsEnglisCh(string input)
        {
            Regex regex = new Regex("^[A-Za-z]+$");
            return regex.IsMatch(input);
        }
        public static string usingstring(string str, int useint)
        {
            if (str.Length > useint)
            {
                str = str.Substring(0, useint);
                return str;
            }
            else
            {
                return str;
            }


        }


    }

}

